package com.api.shopapi.mapper;

import com.api.shopapi.entity.SBJSleepReport;
import com.api.shopapi.entity.dto.SBJSleepReportDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface SBJSleepReportMapper {

    @Insert("insert into sbj_sleep_report (SleepReportCode,HeaderCode,DeviceId,Sober,LightSleep,DeepSleep,StartBedTime," +
            "EndBedTime,SleepTime,SleepHours,SleepQuality,RespiratoryRate,HeartRate,BodyMove,BedAway,Abnormal,Advice,AddTime) values " +
            "(#{sleepReport.SleepReportCode},#{sleepReport.HeaderCode},#{sleepReport.DeviceId},#{sleepReport.Sober},#{sleepReport.LightSleep}," +
            "#{sleepReport.DeepSleep},#{sleepReport.StartBedTime},#{sleepReport.EndBedTime},#{sleepReport.SleepTime},#{sleepReport.SleepHours}," +
            "#{sleepReport.SleepQuality},#{sleepReport.RespiratoryRate},#{sleepReport.HeartRate},#{sleepReport.BodyMove},#{sleepReport.BedAway}," +
            "#{sleepReport.Abnormal},#{sleepReport.Advice},#{sleepReport.AddTime})")
    int insert(@Param("sleepReport") SBJSleepReport sleepReport);


    @Select("select * from sbj_sleep_report ss left join yj_header yh on ss.HeaderCode = yh.HeaderCode where " +
            "ss.DeviceId=#{deviceId} " +
            "and ss.AddTime between #{startTime} and #{endTime} " +
            "and yh.Name='SleepReport' " +
            "order by ss.AddTime desc")
    List<SBJSleepReportDTO> getSleepReportPageByDeviceId(@Param("deviceId") String deviceId, @Param("startTime") String startTime, @Param("endTime") String endTime);

}
